package com.example.designpattenexample.mixpatten.example1;

public class DeductionFacade {

    private static StrategyMan getDeductionType(Trade trade) {
        if (trade.getTradeNo().startsWith("000"))
            return StrategyMan.SteadyDeduction;
        else
            return StrategyMan.FreeDeduction;
    }

    public static void deduct(ICard card, Trade trade) {
        StrategyMan deductionStrategy = getDeductionType(trade);
        IDeduction deduction = StrategyFactory.getDeduction(deductionStrategy);

        if (deduction.exec(card, trade)) {
            System.out.println("============交易凭证======");
            System.out.println("交易编号：" + trade.getTradeNo() + "交易成功");
            System.out.println("交易金额：" + trade.getAmount());
        } else {
            System.out.println("============交易失败，余额不足======");
        }
    }

}
